package com.szcatic.ework.controller.auth;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szcatic.ework.service.UserService;
import com.szcatic.ework.vo.User;

/**
 * 用户管理Controller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("auth/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private HttpServletRequest request;
	/**
	 * 用户管理初始化页面
	 * @return
	 */
	@RequestMapping(value={"","index"})
	@RequiresPermissions("auth:user:select")
	public String index() {
		return "auth/user";
	}
	
	/**
	 * 查询用户列表
	 * @return
	 */
	@RequestMapping(value={"queryUserList"})
	@RequiresPermissions("auth:user:query")
	@ResponseBody
	public Map<String,Object> queryUserList() {
		PageHelper.startPage(Integer.valueOf(request.getParameter("page")), Integer.valueOf(request.getParameter("limit")));
		List<User> userList= userService.queryUserList();
		PageInfo<User> pageInfo=new PageInfo<User>(userList);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("count", pageInfo.getTotal());
		map.put("data", pageInfo.getList());
		map.put("code", "0"); //成功的状态码
		map.put("msg", "");
		return map;
	}
	
}
